package com.cjw.pojo.assembler;

import com.cjw.pojo.dto.database.UserDTO;
import com.cjw.pojo.dto.person.UserDetailDTO;
import com.cjw.pojo.entity.database.User;
import com.cjw.pojo.entity.person.UserDetail;
import com.cjw.util.BeanUtils;
import lombok.Data;

@Data
public class UserAssembler {
    public static UserDetailDTO toUserDetailDTO(UserDetail userDetail, UserDTO user) {
        UserDetailDTO userDetailDTO = new UserDetailDTO();
        UserDetailDTO copy = BeanUtils.copy(userDetail, userDetailDTO.getClass());
        if (copy.getSex() == null)
            copy.setSex(null);
        else if (copy.getSex().equals("男"))
            copy.setSex("1");
        else if (copy.getSex().equals("女"))
            copy.setSex("2");
        else
            copy.setSex(null);
        copy.setUserName(user.getUserName());
        return copy;
    }
}
